/*
 * LoginController.java
 *
 * Copyright 2012 the original author or authors(ninglong).
 *
 * Licensed under the org.geek.login.web, Version 1.0 (the "License");
 *
 */
package org.geek.login.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.geek.common.base.BaseController;
import org.geek.common.entity.Menu;
import org.geek.common.util.TreeUtil;
import org.geek.module.service.IModuleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p></p>
 * @author ninglong bhd2973@qq.com
 * @version V1.0
 */
@Controller
public class LoginController extends BaseController{
	
	@Resource
	private IModuleService moduleService;

	@RequestMapping(value="index.jhtml",method = RequestMethod.GET)
	@Override
	public String initPage(HttpServletRequest request, ModelMap model) {
		List<Menu> list = moduleService.getModules2Menu(0);
		model.put("nav", TreeUtil.getTree(list, 1));
//		model.put("nav",TreeUtil.getDesktopTree(list,1) );
		return "index";
	}
	
	@RequestMapping(value="loadActions.jhtml",method = RequestMethod.POST)
	@ResponseBody
	public Object loadActions(int moduleId,String owerType){
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		Map<String,Object> map = new HashMap<String, Object>();
//		name: button.enname,
//        text: button.name,
//        cls: button.cls,
//        iconCls: button.icon,
//        tooltip: button.tooltip,
//        handler: button.method,
//        param: button.param,
		map.put("ename", "ename");
		map.put("name", "生成的");
		map.put("icon", "add");
		map.put("handler", "addFn");
		map.put("tooltip", "我是生成的哦");
		map.put("param", "ename");
		list.add(map);
		map = new HashMap<String, Object>();
		map.put("ename", "ename");
		map.put("name", "生成的1");
		map.put("icon", "edit");
		map.put("handler", "editFn");
		map.put("tooltip", "我是生成的哦1");
		list.add(map);
		return list;
	}
}